﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_DetailCate:IData<tbl_DetailCate>
    {
        public Ctbl_DetailCate(String myconnecString) : base(myconnecString) { }

        protected override int InsertOnSubmit(tbl_DetailCate item, int t)
        {
            return connec.ExecuteNonQuery("ProDetailCate", CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@" + tbl_DetailCate.c_Description, item.Description), new SqlParameter("@" + tbl_DetailCate.c_IdCat, item.IdCat),
                new SqlParameter("@" + tbl_DetailCate.c_IdDetail, item.IdDetail), new SqlParameter("@" + tbl_DetailCate.c_IdLang, item.IdLang),
                new SqlParameter("@" + tbl_DetailCate.c_isActive, item.IsActive), new SqlParameter("@" + tbl_DetailCate.c_orderId, item.OrderId),
                new SqlParameter("@" + tbl_DetailCate.c_Title, item.Title));
        }
        /// <summary>
        /// Find theo khoa ngoai
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public override List<tbl_DetailCate> GetAll(tbl_DetailCate item)
        {
            return GetAll().FindAll(p=>p.IdCat==item.IdCat);
        }

        public override tbl_DetailCate GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p=>p.IdDetail==Convert.ToInt32(id));
        }

        public override tbl_DetailCate GetItem(IDataReader dr)
        {
            tbl_DetailCate obj = new tbl_DetailCate();
            obj.Description = dr[tbl_DetailCate.c_Description].ToString();
            obj.IdCat=Convert.ToInt32(dr[tbl_DetailCate.c_IdCat]);
            obj.IdDetail = Convert.ToInt32(dr[tbl_DetailCate.c_IdDetail]);
            obj.IdLang = Convert.ToInt32(dr[tbl_DetailCate.c_IdLang]);
            obj.IsActive = Convert.ToInt32(dr[tbl_DetailCate.c_isActive]);
            obj.OrderId = Convert.ToInt32(dr[tbl_DetailCate.c_orderId]);
            obj.Title = dr[tbl_DetailCate.c_Title].ToString();
            return obj;
        }

        public override List<tbl_DetailCate> GetAll()
        {
            return GetAll(this.strSelect+tbl_DetailCate.b_tbl_DetailCate,CommandType.Text);
        }
    }
}
